<CFSET DATETODAY = #CreateODBCDate(NOW())#>
<CFSET TIMETODAY = #TimeFormat(NOW(),'hh:mm:ss')#>
<cfset ok = TRUE>
<cftransaction action="begin">
	<cftry>
        <CFQUERY NAME="CREATEPMFFILE" DATASOURCE="#CLIENT.COMPANY_DSN#">
            INSERT INTO CINWSFILE
            	(DOCNUMBER, FILENAME, DATEFROM, DATETO, REMARKS, DEPTCODE ,RECCREATEDBY, RECDATECREATED,
            		USERID, DATELASTUPDATE, TIMELASTUPDATE)
            VALUES(
            	   '#Form.DOCNUM#',
                   '#Form.FILENAME#',
                   #CreateODBCDate(Form.FROM)#,
                   #CreateODBCDate(Form.TO)#,
                   '#Form.remarks#',
                   '#Form.deptcode#',
                   '#CLIENT.USERID#',
                   #DATETODAY#,
                   '#CLIENT.USERID#',
                   #DATETODAY#,
                   '#TIMETODAY#'
                   )
        </CFQUERY>      
        <cfloop list=#Form.SSELSELECTEDEMPLOYEES# index="theSelection">
        	<cfset pid = ListGetAt( theSelection, 1, '~' ) >
            <CFQUERY NAME="addEmp" DATASOURCE="#CLIENT.COMPANY_DSN#">
                INSERT INTO CINWSFILEperson
                	( WSFILENO, PERSONNELIDNO, RECCREATEDBY, RECDATECREATED, 
                    	USERID, DATELASTUPDATE, TIMELASTUPDATE)
                VALUES(
                       '#Form.DOCNUM#',
                       '#pid#',
                       '#CLIENT.USERID#',
                       #DATETODAY#,
                       '#CLIENT.USERID#',
                       #DATETODAY#,
                       '#TIMETODAY#'
                       )
            </CFQUERY>
      </cfloop>


      <cfcatch>
       	<cfset ok = false>
      <CFSET client.err = "#cfcatch.Detail#">
      </cfcatch>
  </cftry>
   
<cfif ok>
  <cftransaction action="commit">
  <CFSET client.err = "&nbsp; &nbsp; Form (#Form.FILENAME#) Successfully Created.">
  <cflocation url="#client.domain#eworksched/manning/index.cfm" addtoken="no">
<cfelse>
  <cftransaction action="rollback">  
  <cflocation url="#client.domain#eworksched/manning/index.cfm?re=" addtoken="no">
</cfif>
</cftransaction>


